package com.flymobi.admin;

import java.util.List;

import com.flymobi.fw.modules.SM;
import com.flymobi.po.Manager;
import com.flymobi.po.Roles;
import com.flymobi.po.SysMenu;
import com.flymobi.po.SysPower;
import com.flymobi.util.C;
import com.flymobi.util.WebContext;

/**
 * 
 * 
 * Title:
 * 
 * Description:
 * 
 * Copyright: Copyright (c) 2008
 * 
 * @author haoxz11
 * @created Oct 21, 2008 11:16:42 AM
 * @version $Id: SysPowerAction.java,v 1.1 2010/04/09 03:27:08 airsou Exp $
 */
public class SysPowerAction extends WebAction {
	private String[] selectitems;


	/**
	 * Comment for <code>serialVersionUID</code>
	 */
	private static final long serialVersionUID = 1L;

	@Override
	public String webProcess(WebContext context, Manager manager) {
		if ("list".equals(method)) {
			/*Manager man =SM.ManagerService.load(
					id);*/
			Roles roles=SM.RolesService.get(id);
			context.put("roles", roles);
			List<SysPower> sysPowerList = SM.SysPowerService.list(id);
			List<SysMenu> sysMenuList = SM.SysMenuService.list(C.SYS_MENU.FATHER);
			for (SysMenu sysMenu : sysMenuList) {
				List<SysMenu> subSysMenuList=SM.SysMenuService.list(String.valueOf(sysMenu.getId()));
				sysMenu.setSysMenuList(subSysMenuList);
				for(SysPower sysPower:sysPowerList){
					if(sysPower.getSysMenuId().equals(sysMenu.getId())){
						sysMenu.setSysPower(sysPower);
						for (SysMenu subSysMenu : subSysMenuList) {
							for(SysPower sysPower2:sysPowerList){
								if(sysPower2.getSysMenuId().equals(subSysMenu.getId())){
									subSysMenu.setSysPower(sysPower2);
									break;
								}
							}
						}
						break;
					}
				}
			}
			context.put("sysMenuList", sysMenuList);
//			context.put("man", man);
			return "list";
		} else if ("save".equals(method)) {
			/*Manager man =SM.ManagerService.load(
					id);*/
			SM.SysPowerService.deleteByRolesId(id);
			if (selectitems != null) {
				for (String idx : selectitems) {
					SysPower sysPower=new SysPower();
					sysPower.setRolesId(new Long(id));
					sysPower.setSysMenuId(new Long(idx));
					SM.SysPowerService.save(sysPower);
				}
			}
			context.put("rmsg", C.TEXT.SAVE_SUCCESS);
			return "listroles";
		}else {
			method = "list";
			return this.webProcess(context, manager);
		}
	}

	public String[] getSelectitems() {
		return selectitems;
	}

	public void setSelectitems(String[] selectitems) {
		this.selectitems = selectitems;
	}

	/* (non-Javadoc)
	 * @see com.camel.admin.WebAction#getSysLog()
	 */
	@Override
	public String getSysLog() {
		// TODO Auto-generated method stub
		return null;
	}
}
